local skel = fk.CreateSkill {
  name = "emo__lianhua",
}

Fk:loadTranslationTable{
  ["emo__lianhua"] = "莲华",
  [":emo__lianhua"] = "当你受到伤害时，可弃置两张牌后获得本回合进入弃牌堆的一张牌，这些牌若类别均不同，你令此伤害-1。",

  ["#emo__lianhua-cost"] = "莲华：你可弃2张牌，再获得弃牌堆1张牌，若3张类型不同，受伤害-1",
  ["#emo__lianhua-get"] = "莲华：选择1张获得！",

  ["$emo__lianhua1"] = "刀兵水火，速离身形。",
  ["$emo__lianhua2"] = "体有金光，覆映吾身。",
}

skel:addEffect(fk.DamageInflicted, {
  anim_type = "drawcard",
  can_trigger = function (self, event, target, player, data)
    return target == player and player:hasSkill(skel.name) and #player:getCardIds("he") > 1
  end,
  on_cost = function (self, event, target, player, data)
    local cards = player.room:askToDiscard(player, {
      min_num = 2, max_num = 2, skill_name = skel.name, include_equip = true, cancelable = true,
      skip = true, prompt = "#emo__lianhua-cost",
    })
    if #cards == 2 then
      event:setCostData(self, {cards = cards})
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local cards = event:getCostData(self).cards
    if not cards then return  end
    local types = table.map(cards, function(id) return Fk:getCardById(id).type end)
    room:throwCard(cards, skel.name, player, player)
    if player.dead then return end
    local get = {}
    room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function(e)
      for _, move in ipairs(e.data) do
        if move.toArea == Card.DiscardPile then
          for _, info in ipairs(move.moveInfo) do
            if room:getCardArea(info.cardId) == Card.DiscardPile then
              table.insertIfNeed(get, info.cardId)
            end
          end
        end
      end
      return false
    end, Player.HistoryTurn)
    if #get == 0 then return end
    local cid = room:askToChooseCard(player, {
      target = player, skill_name = skel.name, prompt = "#emo__lianhua-get",
      flag = { card_data = { { "pile_discard", get } } }
    })
    local all = {Fk:getCardById(cid).type}
    room:obtainCard(player, cid, true, fk.ReasonPrey, player, skel.name)
    for _, t in ipairs(types) do
      table.insertIfNeed(all, t)
    end
    if #all == 3 then
      data:changeDamage(-1)
    end
  end,
})

return skel
